package com.neusoft.demo3;

/**
 * 添加员工信息、根据id查询某个员工、查询所有员工信息、修改某个员工信息
 */
public class EmployeeManager {
    private Employee[] emps;
    int count;

    public EmployeeManager() {
        emps = new Employee[3]; //创建一个数组容器用于保存员工对象
    }
    /**
     * 添加员工信息
     * @param employee 对象
     */
    public void add(Employee employee) {
        if(count < emps.length) {
            emps[count] = employee;
            count++;
            System.out.println("add success");
        }else {
            System.out.println("add error");
        }
    }



    /**
     * 查询所有员工信息
     * @return
     */
    public Employee[] getQueryAll() {
        Employee[] employees = new Employee[3]; //定义一个新的容器
        for(int i = 0;i<emps.length;i++) {
             employees[i] = emps[i];
        }
        return employees;
    }

    /**
     * 根据id查询某个员工
     * @param id
     * @return
     */
    public Employee getQueryById(int id) {
        Employee e = null;
        for(int i = 0;i < emps.length;i++) {
            if(id == emps[i].getId()){
                e = emps[i];
                break;
            }
        }
        return e;
    }

    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    public Employee update(Employee employee) {
        employee.setName("abc");
        return employee;
    }
}
